<?php

include '../../db.php';
$connect = pg_connect($connectionString);
if (!$connect) {
    echo "connect : A connection to the server could not be established!";
    return false;
}

//$queryString = "SELECT id, serie,number,client_id,emission_date,cancellation_date,subtotal,igv,total FROM sale_header LIMIT 10 OFFSET " . ($_GET["pag"]*10);
//$queryString = "SELECT id, serie,number,client_id,emission_date,cancellation_date,subtotal,igv,total FROM sale_header WHERE name LIKE '%".$_GET['word_search']."%' LIMIT 10 OFFSET " . ($_GET["pag"]*10);
$queryString = 
        "SELECT 
  sale_header.id, 
  sale_header.emission_date, 
  sale_header.total, 
  sale_header.serie, 
  sale_header.number, 
  sale_header.cancellation_date, 
  sale_header.igv, 
  sale_header.subtotal, 
  sale_client.fullname as client_id
FROM 
  public.sale_client, 
  public.sale_header
WHERE 
  sale_header.client_id = sale_client.id  AND sale_client.fullname LIKE '%".$_GET['word_search']."%' LIMIT 10 OFFSET " . ($_GET["pag"]*10);


$query = pg_query($connect, $queryString);
if (!$query) {
    echo 'query : ';
    return false;
}
$arrRegistros = pg_fetch_all($query);
echo json_encode($arrRegistros);
$num_fields = pg_num_fields($query);
$num_rows = pg_num_rows($query);

pg_close($connect);
